# -*- coding: utf-8 -*-

import wx
import rememberaboutwnd
import dbhelper
class RememberTaskBar(wx.TaskBarIcon):
    def __init__(self, frameSearchWnd):
        wx.TaskBarIcon.__init__(self)
        self.frameSearchWnd = frameSearchWnd
    
        self.SetIcon(wx.Icon('pic/Remember.png', wx.BITMAP_TYPE_PNG), 'Remember')
        self.Bind(wx.EVT_MENU, self.OnShowSearchWnd, id=1)
        self.Bind(wx.EVT_MENU, self.OnNewDataBase, id=2)
        self.Bind(wx.EVT_MENU, self.OnShowAbout, id=3)
        self.Bind(wx.EVT_MENU, self.OnRememberClose, id=4)
        

    def CreatePopupMenu(self):
        menu = wx.Menu()
        menu.Append(1, u'显示搜索栏')
        menu.Append(2, u'创建数据库')
        menu.Append(3, u'关于')
        menu.Append(4, u'退出')
        return menu
    def OnRememberClose(self, event):
        self.frameSearchWnd.Close()
        self.Destroy()
    def OnShowSearchWnd(self, event):
        if not self.frameSearchWnd.IsShown():
            self.frameSearchWnd.Show()
    def OnShowAbout(self,event):
        aboutWnd = rememberaboutwnd.RememberAboutWnd(self.frameSearchWnd)
        aboutWnd.ShowModal()
        aboutWnd.Destroy()
    def OnNewDataBase(self,event):
        dlg = wx.TextEntryDialog(
                self.frameSearchWnd, u'请输入你要创建的新数据库的名字：',
                u'创建数据库', '')
        if dlg.ShowModal() == wx.ID_OK:
            dbName = dlg.GetValue().strip()
            if (dbName.isalnum()):
                #db = dbhelper.DbHelper(dbName,new=True)
                #db.Disconnect()
                error = wx.MessageDialog(self.frameSearchWnd, u'TO be complete',
                                                       u'yeah',
                                                       wx.OK | wx.ICON_INFORMATION
                                                       )
                error.ShowModal()
                error.Destroy()
            else:
                error = wx.MessageDialog(self.frameSearchWnd, u'数据库的名字必须是数字、字母组成',
                                       u'数据库名字格式错误',
                                       wx.OK | wx.ICON_INFORMATION
                                       )
                error.ShowModal()
                error.Destroy()
        dlg.Destroy()
        
    

